package pkg

import (
	"fmt"
	"github.com/golang-jwt/jwt/v5"
	"time"
)

func CreateJwtToken(id string, duration time.Duration, s string) string {

	type MyCustomClaims struct {
		Foo string `json:"foo"`
		jwt.RegisteredClaims
	}
	claims := MyCustomClaims{
		id,
		jwt.RegisteredClaims{
			// A usual scenario is to set the expiration time relative to the current time
			ExpiresAt: jwt.NewNumericDate(time.Now().Add(duration)),
		},
	}

	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
	ss, err := token.SignedString(s)
	fmt.Println(ss, err)
	return ss
}

func AuthJwtToken(bytes string, s string) {
	type MyCustomClaims struct {
		Foo string `json:"foo"`
		jwt.RegisteredClaims
	}

	token, _ := jwt.ParseWithClaims(s, &MyCustomClaims{}, func(token *jwt.Token) (interface{}, error) {
		return []byte(bytes), nil
	})
	fmt.Print(token)

}
